<?php
/**
 *课程调用类
 *@author sulwan@126.com
 *@date 2009-11-20
 */

 class Article extends Application{
    public $Classlist;

 public function __construct() {
    parent::__construct();
 }



/**
 * 检测用英文目录名是否可使用
 *
 * @param string $ename
 * @return bool	如果可用，返回true，否则false
 */
public static function checkEname($ename){
	$db = new Happy_db();
	if ( empty($ename) ){
		return false;
	}
	$sql = "SELECT * FROM `#happy_article_category` WHERE `ename`='".mysql_escape($ename)."'";
	$r = $db->getRow($sql);
	if ( empty($r) ){
		return true;
	}
	else {
		return false;
	}
}

/**
 *添加分类
 */
public function add_articleCategory($data) {
	$data = array_map('mysql_escape',$data);
	$sql = "INSERT INTO `#happy_article_category`(`".implode("`,`",array_keys($data))."`)VALUES('".implode("','",array_values($data))."')";
	$id = $this->_db->execute($sql);
	return $id;
}


/**
 *查看有哪些栏目
 */
public function articleTreeSort(){
    $this->articleclassSort();
    $temp = $this->Classlist->getTreeList();
    foreach ($temp as $k => $v) {					//添加深度
        $data[] = $v->obj;
        $data[$k]['depth'] = $v->depth;
		$fields[] = 'pid = '.$data[$k]['id'];
		$data[$k]['icon'] = $this->seachFields($fields);
		unset($fields);
    }
        return $data;
}

/**
*获取现有模块
*/
public function articleModulegory() {
    $sql = "SELECT * FROM #happy_article_category;";
    $rs = $this->_db->getAll($sql);
    return $rs;
}

/**
 *栏目数据赋值
 */
public function articleclassSort() {
     $rsList = $this->articleModulegory();
     $this->Classlist = new CCategory();
     $this->Classlist->assign ($rsList, 'id', 'pid', 'taxis');
}

/**
 *检索是否存存在指定字段的指定值
 */
public function seachFields($fields) {
	$where = is_array($fields) ? implode(' AND ', $fields) : $fields;
	$where = empty ($where) ? '' : ' WHERE ' . $where;
    $sql = "SELECT * FROM #happy_article_category";
	$sql .= $where;
    $data = $this->_db->getOne($sql);
	if(!empty($data)) {
		return TRUE;
	}
	return FALSE;
}


}
 ?>